import React, { useEffect, useState } from 'react';
import { useAddKey } from '../hooks/index';
import { Input, Space } from 'antd';
import { getTime } from '../../utils/time';
const { Search } = Input;
export function addShopTable(fn) {
  return (Com) => {
    return () => {
      const [list, setList] = useState([]);
      useEffect(() => {
        fn().then((res) => {
          console.log(res);
          setList(useAddKey(res.data.data));
        });
      }, []);

      // 搜索
      const onSearch = (value) => {
        console.log(value);
        fn({ value }).then((res) => {
          console.log(res, 'res');
          setList(useAddKey(res.data));
        });
      };

      // 删除
      const del = (id) => {
        const data = JSON.parse(JSON.stringify(list));
        data.forEach((item, index) => {
          if (item.id == id) {
            data.splice(index, 1);
          }
        });
        setList(data);
      };

      return (
        <div>
          <Search
            placeholder="input search text"
            allowClear
            enterButton="搜索"
            size="large"
            onSearch={onSearch}
          />

          <Com
            // addList={addList}
            del={del}
            //   change={change}
            data={list}
          ></Com>
        </div>
      );
    };
  };
}
